newMod("help")

--Global
conf_help = "help/"

--Variables
help.var("list", "")

--Utilities
function util.loadhelp()
	for act, fn in pairs(acts) do
		file = io.open(conf_help..act..".help", "r")
		if file then
			local s = file:read()
			file:close()
			help.add(act, s)
		end
	end

	for act, fn in pairs(admacts) do
		file = io.open(conf_help..act..".help", "r")
		if file then
			local s = file:read()
			file:close()
			help.add(act, s)
		end
	end

end

--Help.add("mod", "command", "description")
function help.add(c, d)
	if help[c] then return nil end
	if acts[c] then
		help[c] = {description = d}
	elseif cmd_priv[c] then
		help[c] = {description = d}
		help[c].access = ""
		for k, v in pairs(cmd_priv[c]) do
			help[c].access = k
			break
		end
	end
end

--Admin - Command "/help command"

function act_help(p, typ, cmd)
	if not cmd then cmd =  "" end
	cmd = string.gsub(cmd, "%s", "")
	local t = string.gsub(cmd, "_", "")
	if t == "" then
		msg2(p, "All available commands: "..help.list)
		msg2(p, "Type /help command to get the description on that particular command.")
		return
	end

	if help[t] then
		msg2(p, "\""..cmd.."\"".." usage: "..help[t].description)
		if help[t].access then
			msg2(p, "Only users with an access mask of \""..help[t].access.."\" or greater can access this command")

			--if not adminhierarchy(help[t].access)[admins[p]] or admins[p] == help[t].access then
			--	msg2(p, "You have enough privilege to access this command")
			--else
			--	msg2(p, "You do not have enough privilege to access this command")
			--end

		end
	else
		if acts[t] or admacts[t] then
			msg2(p, "The Command \""..cmd.."\" exists but does not have a help file")
		else
			msg2(p, "The Command \""..cmd.."\" does not exist.")
			parseCmd("help", false, {p})
		end
	end

end
--Hooks

function hook_init_help()
	--print(help.name.." Initiated")

	for act, fn in pairs(acts) do
		if help.list == "" then help.list = act else
			help.list = help.list..", "..act
		end
	end

	for act, fn in pairs(admacts) do
		help.list = help.list..", "..act
	end

	util.loadhelp()
	--print(help.list)
end

return help.name
